package com.bdqn.BookManage.dao.impl;

import com.bdqn.BookManage.dao.OrderSettlementsDao;
import com.bdqn.BookManage.po.OrderSettlements;
import com.bdqn.BookManage.util.DBUtil;

import java.sql.SQLException;
import java.util.List;

/**
 * @author : CP
 * @version: 1.0
 * @program : BookManage
 * @description : 订单结算接口实现类
 * @date : 2020-07-31 15:02
 **/
public class OrderSettlementsDaoImpl implements OrderSettlementsDao {
    @Override
    public boolean add(OrderSettlements orderSettlements) {
        String sql = "insert into ordersettlements values(null,?,?,?,?,?,?,?,?,?)";
        Object [] obj = {orderSettlements.getOrderId(),orderSettlements.getSettlementNo(),
                orderSettlements.getSettlementType(),orderSettlements.getOrderMoney(),
                orderSettlements.getSettlementMoney(),orderSettlements.getCreateTime(),
                orderSettlements.getIsFinish(),orderSettlements.getFinishTime(),orderSettlements.getRemarks()};
        return DBUtil.connZsg(sql,obj);
    }

    @Override
    public OrderSettlements queryById(String id) {
        OrderSettlements orderSettlements = null;
        String sql = "select * from `ordersettlements` where orderId = ?";
        Object [] obj = {id};
        List<OrderSettlements> list = (List<OrderSettlements>) DBUtil.queryAll(sql, obj, OrderSettlements.class);
        if(list.size() >0){
            orderSettlements = list.get(0);
        }
        return orderSettlements;
    }

    @Override
    public boolean amend(OrderSettlements orderSettlements) {
        String sql = "update `ordersettlements` set settlementType=?,orderMoney=?,settlementMoney=?," +
                "createTime=?,isFinish=?,finishTime=?,remarks=? where orderId=?";
        Object [] obj = {orderSettlements.getSettlementType(),orderSettlements.getOrderMoney(),
                orderSettlements.getSettlementMoney(),orderSettlements.getCreateTime(),
                orderSettlements.getIsFinish(),orderSettlements.getFinishTime(),
                orderSettlements.getRemarks(),orderSettlements.getOrderId()};
        return DBUtil.connZsg(sql,obj);
    }
}
